package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.Section;
import dao.SectionImpl;

/**
 * Servlet implementation class UpdateSection
 */
@WebServlet(name="UpdateSection",
urlPatterns= {"/servlet/UpdateSection"},
loadOnStartup = 1)
public class UpdateSection extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateSection() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		response.setContentType("text/html,charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String id=request.getParameter("id");
		String name=request.getParameter("name");
		String type=request.getParameter("type");
		String phone=request.getParameter("phone");
		String fax=request.getParameter("fax");
		String tsection=request.getParameter("tsection");
		String ftime=request.getParameter("ftime");
		String des=request.getParameter("des");
		Section section=new Section();
		section.setId(id);
		section.setName(name);
		section.setType(type);
		section.setPhone(phone);
		section.setFax(fax);
		section.setTsection(tsection);
		section.setFtime(ftime);
		section.setDes(des);
		SectionImpl sectionbean=new SectionImpl();
		int n=sectionbean.update(section);
		if(n>0) {
			request.getRequestDispatcher("/section.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("/error.jsp").forward(request, response);
		}
	}

}
